package com.pp.demo.module.user.controller;


import com.pp.demo.common.util.SignatureUtils;
import com.pp.demo.module.user.entity.User;
import com.pp.demo.module.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pzh
 * @since 2025-06-11 21:29:42
 */
@Api(tags = "用户管理")
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("列出所有用户")
    @GetMapping("listUser")
    public List<User> listUser(@RequestParam String name){
        log.info("列出所有用户: {}", name);

        return userService.list();
    }

    public static void main(String[] args) {
        String appId = "app1";
        String appSecret = "secret123";
        String timestamp = String.valueOf(System.currentTimeMillis());
        String nonce = UUID.randomUUID().toString();

        Map<String, String> map = new HashMap<>();
        map.put("name", "test");
        String sign = SignatureUtils.generateSignature(appId, appSecret, timestamp, nonce, map);

        System.out.println(timestamp);
        System.out.println(nonce);
        System.out.println(sign);
    }
}
